package src.data;

import java.util.Set;
import src.domain.MailBox;
import src.domain.PostOffice;
import src.domain.User;

public class MailBoxSRV {
	
	private static MailBoxDAO dao;
	static {
		dao = MailBoxDAO.getInstance();
	}
	
	public static MailBox getByID(long idMailBox){
		MailBox mailBox=new MailBox();
		mailBox.setId(idMailBox);
		return dao.getByID(mailBox);
	}
	
	public static MailBox getByName(String nameMailBox){
		MailBox mailBox=new MailBox();
		mailBox.setName(nameMailBox);
		return dao.getByName(mailBox);
	}
	
	public static MailBox getByNameAndPass(String nameMailBox,String passMailBox){
		MailBox mailBox=new MailBox();
		mailBox.setName(nameMailBox);
		mailBox.setPass(passMailBox);
		return dao.getByNameAndPass(mailBox);
	}
	
	public static void save(String name, String pass,boolean active, User user,Set<PostOffice> postOffices){
		MailBox mailBox = new MailBox();
		mailBox.setName(name);
		mailBox.setPass(pass);
		mailBox.setActive(active);
		mailBox.setUser(user);
		mailBox.setPostOffices(postOffices);
		dao.save(mailBox);	
	}
	
	public static void update(MailBox mailBox){
			dao.update(mailBox);
	}
	
	public static void delete(long idMailBox){
		dao.delete(getByID(idMailBox));
	}
	
	public static Set<MailBox> getAll(){
		return dao.getAll();
	}
	
	public static Set<PostOffice> getUnassignedPostOffices(Long id) {
		MailBox mailBox=new MailBox();
		mailBox.setId(id);
		return dao.getUnassignedPostOffices(mailBox);
	}
	
	
	public static Set<MailBox> getMailBoxesByPostOffice(long idPostOffice) {
		PostOffice p=new PostOffice();
		p.setId(idPostOffice);
		return dao.getMailBoxesByPostOffice(p);

	}
	
	public static Set<MailBox> getMailBoxesByPostOffice(PostOffice postOffice) {
		
		return dao.getMailBoxesByPostOffice(postOffice);

	}
	
	public static Set<MailBox> getMailBoxes(String name) {
		MailBox mailBox=new MailBox();
		mailBox.setName(name);
		return dao.getMailBoxes(mailBox);
	}
	
	public static Set<MailBox> getMailBoxesByUser(long idUser) {
		User user=new User();
		user.setId(idUser);
		return dao.getMailBoxesByUser(user);
	}
	
}
